package com.tn.cron;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.taskqueue.Queue;
import com.google.appengine.api.taskqueue.QueueFactory;
import com.google.appengine.api.taskqueue.TaskOptions;

public class PaymentCronServlet extends HttpServlet {
	private SimpleDateFormat dateFormatter = new SimpleDateFormat(
			"yyyy-MM-dd'T'HH:mm:ss.SSSZ");

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		System.out.println("PaymentCronServlet.doGet() => Cron job started at "
				+ dateFormatter.format(new Date()));
		Queue queue = QueueFactory.getQueue("payment-task-generator");
		TaskOptions task = TaskOptions.Builder.withDefaults();
		// set the URL over here
		task.url("/paymentReportTaskGenerator");
		queue.add(task);
		System.out
				.println("PaymentCronServlet.doGet() => Cron job completed at "
						+ dateFormatter.format(new Date()));
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doGet(req, resp);
	}
}
